﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
using Topshelf.ServiceConfigurators;
using Topshelf.HostConfigurators;
using System.IO;
using log4net.Config;
using log4net;
using System.Diagnostics; 

namespace RPCenter.UpdaterService
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        { 
            //日志配置文件
            Log4netHelper.Repository = LogManager.CreateRepository("NETCoreRepository");
            XmlConfigurator.Configure(Log4netHelper.Repository, new FileInfo(Environment.CurrentDirectory + "/Config/log4net.config")); 
            HostFactory.Run(x =>                                 //1
            {
                //x.UseLog4Net("Log4Net.config");

                x.Service<TownCrier>(s =>                        //2
                {
                    s.ConstructUsing(name => new TownCrier());     //3
                    s.WhenStarted(tc => tc.Start());              //4
                    s.WhenStopped(tc => tc.Stop());               //5
                });
                x.RunAsLocalSystem();                            //6
                 
                x.SetDescription("RPCenter 自动更新服务");        //7
                x.SetDisplayName("RPCenter.UpdaterService");                       //8
                x.SetServiceName("RPCenter.UpdaterService");                       //9
            });
            Console.Read();
        }

    }
}
